// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

package com.netease.yunxin.kit.chatkit.ui.custom;

import com.google.gson.Gson;
import com.netease.yunxin.kit.chatkit.ui.ChatMessageType;
import com.netease.yunxin.kit.chatkit.ui.bean.GiftMessageBean;
import com.netease.yunxin.kit.common.utils.FileUtils;

import org.json.JSONException;
import org.json.JSONObject;

public class GiftAttachment extends CustomAttachment {
  private GiftMessageBean giftMessageBean;
  public GiftAttachment() {
    super(ChatMessageType.CUSTOM_GIFT);
  }

  public GiftAttachment(GiftMessageBean giftMessageBean){
    this();
    this.giftMessageBean = giftMessageBean;
  }

  @Override
  protected void parseData(JSONObject data) {
    try {
      this.giftMessageBean = new Gson().fromJson(data.toString(),GiftMessageBean.class);
    } catch (Exception ignored) {

    }
  }

  @Override
  protected JSONObject packData() {
    try {
      return new JSONObject(new Gson().toJson(giftMessageBean));
    } catch (Exception exception) {
      return new JSONObject();
    }
  }

  @Override
  public String getContent() {
    return "[礼物消息]";
  }

  public void setData(GiftMessageBean giftMessageBean){
    this.giftMessageBean = giftMessageBean;
  }

  public GiftMessageBean getData(){return giftMessageBean;}
}
